package tech.zhiwei.frostmetal.core.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

/**
 * 将 boolean 类型转换为 int 类型
 *
 * @author LIEN
 * @since 2024/11/9
 */
public class BooleanToIntegerDeserializer extends JsonDeserializer<Integer> {
    @Override
    public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        boolean value = p.getBooleanValue();
        // true 转为 1, false 转为 0
        return value ? 1 : 0;
    }
}
